<?php
/* --------------------------------------------------------------
   PropertiesCombisContentView.inc.php 2011-12-20 tb@gambio
   Gambio GmbH
   http://www.gambio.de
   Copyright (c) 2011 Gambio GmbH
   Released under the GNU General Public License (Version 2)
   [http://www.gnu.org/licenses/gpl-2.0.html]
   --------------------------------------------------------------
*/

class PropertiesCombisContentView extends ContentView
{
	function PropertiesCombisContentView() 
	{
		$this->v_coo_combis_admin_control = MainFactory::create_object('PropertiesCombisAdminControl');
	}
	
	function get_html($p_param)
	{
		$c_products_id			= (int)$p_param['products_id'];
		$c_properties_combis_id = (int)$p_param['properties_combis_id'];
		
		if($c_properties_combis_id > 0)
		{
			# prepare dropdowns for maybe existing default values
			$t_selected_properties_values_ids_array = array();
			
			# load combis data by optional given properties_combis_id
			$t_combis_full_struct = $this->v_coo_combis_admin_control->get_combis_full_struct($c_properties_combis_id, $_SESSION['languages_id']);
			
			# collect selected properties_values_ids
			foreach($t_combis_full_struct['COMBIS_VALUES'] as $t_item_array) {
				$t_selected_properties_values_ids_array[] = $t_item_array['properties_values_id'];
			}

			$t_sort_order				= $t_combis_full_struct['sort_order'];
			$t_combi_model				= $t_combis_full_struct['combi_model'];
			$t_combi_quantity			= $t_combis_full_struct['combi_quantity'];
			$t_combi_weight				= $t_combis_full_struct['combi_weight'];
			$t_combi_price_type			= $t_combis_full_struct['combi_price_type'];
			$t_combi_price				= $t_combis_full_struct['combi_price'];

			$t_vpe_value				= $t_combis_full_struct['vpe_value'];
			$t_products_vpe_id			= $t_combis_full_struct['products_vpe_id'];
			$t_vpe_array				= $this->v_coo_combis_admin_control->get_vpe_selection_array($_SESSION['languages_id'], $t_combis_full_struct['products_vpe_id']);
			
			$t_combi_shipping_id		= $t_combis_full_struct['combi_shipping_status_id'];
			$t_shipping_status_array	= $this->v_coo_combis_admin_control->get_shipping_status_array($_SESSION['languages_id']);
			$t_combi_image				= $t_combis_full_struct['combi_image'];
		}
		else
		{
			# no default values for value-dropdowns
			$t_selected_properties_values_ids_array = array();

			$t_sort_order				= '1';
			$t_combi_model				= '0';
			$t_combi_quantity			= '0';
			$t_combi_weight				= '0.0000';
			$t_combi_price_type			= '';
			$t_combi_price				= '0.00';

			$t_vpe_value				= '';
			$t_products_vpe_id			= '';
			$t_vpe_array				= $this->v_coo_combis_admin_control->get_vpe_selection_array($_SESSION['languages_id']);
			
			$t_combi_shipping_id		= '0';
			$t_shipping_status_array	= $this->v_coo_combis_admin_control->get_shipping_status_array($_SESSION['languages_id']);
			$t_combi_image				= '';
		}
		
		#build dropdowns-part
		$t_properties_dropdowns = $this->v_coo_combis_admin_control->get_admin_select_detailed($c_products_id);
		
		$t_content_data_array = array(
									'properties_combis_id'	=> $c_properties_combis_id,
									'products_id'		   	=> $c_products_id,
									'properties_dropdowns' 	=> $t_properties_dropdowns,
									'sort_order' 			=> $t_sort_order,
									'combi_model' 			=> $t_combi_model,
									'combi_quantity' 		=> $t_combi_quantity,
									'combi_weight'			=> $t_combi_weight,
									'combi_price_type' 		=> $t_combi_price_type,
									'combi_price' 			=> $t_combi_price,
									'vpe_value' 			=> $t_vpe_value,
									'products_vpe_id' 		=> $t_products_vpe_id,
									'VPE_DATA'				=> $t_vpe_array,
									'combi_shipping_time_id'=> $t_combi_shipping_id,
									'SHIPPING_STATUS_DATA'	=> $t_shipping_status_array,
									'combi_image'			=> $t_combi_image,									
									'properties_values'		=> $t_selected_properties_values_ids_array
								);
		
		$this->set_content_data("properties_combis_data", $t_content_data_array);
		
		$t_html_output = $this->build_html();
		return $t_html_output;
	}
}
?>